<?php

class Common_Chart_Factory {

    const STRATEGY_DEFAULT = 'google';
    const STRATEGY_GOOGLE = 'google';

    public function __construct() {
    }

    public function create($enm_chart_type, $arr_options = array()) {
        
        $obj_chart = null;
        $obj_strategy = $this->generate_strategy($enm_chart_type);

        if(!is_null($obj_strategy)) {

            if(isset($arr_options['strategy'])) {
                $obj_strategy->import_for_unserialise($arr_options['strategy']);
            }

            $obj_chart = new Common_Chart($obj_strategy);

            if(isset($arr_options['meta'])) {
                $obj_chart->set_meta($arr_options['meta']);
            }

            if(isset($arr_options['width'])) {
                $obj_chart->set_width($arr_options['width']);
            }

            if(isset($arr_options['height'])) {
                $obj_chart->set_height($arr_options['height']);
            }

        }

        return $obj_chart;
    }

    public function generate_strategy($enm_chart_type, $enm_strategy = null) {

        $obj_strategy = null;

        if(empty($enm_strategy)) {
            $enm_strategy = self::STRATEGY_DEFAULT;
        }

        $enm_switch = $enm_strategy . $enm_chart_type;

        switch($enm_switch) {
        case self::STRATEGY_GOOGLE . Common_Chart::TYPE_PIE:
            $obj_strategy = new Common_Chart_Strategy_Google_Pie();
            break;
        case self::STRATEGY_GOOGLE . Common_Chart::TYPE_TREND:
            $obj_strategy = new Common_Chart_Strategy_Google_Trend();
            break;
        case self::STRATEGY_GOOGLE . Common_Chart::TYPE_TREND_VERTICAL_BAR_GROUPED:
            $obj_strategy = new Common_Chart_Strategy_Google_Trend_VerticalBarGrouped();
            break;
        case self::STRATEGY_GOOGLE . Common_Chart::TYPE_TREND_VERTICAL_BAR_STACKED:
            $obj_strategy = new Common_Chart_Strategy_Google_Trend_VerticalBarStacked();
            break;
        case self::STRATEGY_GOOGLE . Common_Chart::TYPE_LINE:
            $obj_strategy = new Common_Chart_Strategy_Google_Line();
            break;
        case self::STRATEGY_GOOGLE . Common_Chart::TYPE_VERTICAL_BAR_GROUPED:
            $obj_strategy = new Common_Chart_Strategy_Google_Bar_VerticalGrouped();
            break;
        case self::STRATEGY_GOOGLE . Common_Chart::TYPE_VERTICAL_BAR_STACKED:
            $obj_strategy = new Common_Chart_Strategy_Google_Bar_VerticalStacked();
            break;
        case self::STRATEGY_GOOGLE . Common_Chart::TYPE_HORIZONTAL_BAR_GROUPED:
            $obj_strategy = new Common_Chart_Strategy_Google_Bar_HorizontalGrouped();
            break;
        case self::STRATEGY_GOOGLE . Common_Chart::TYPE_HORIZONTAL_BAR_DYNAMIC:
            $obj_strategy = new Common_Chart_Strategy_Google_Bar_HorizontalDynamic();
            break;
        case self::STRATEGY_GOOGLE . Common_Chart::TYPE_RADAR:
            $obj_strategy = new Common_Chart_Strategy_Google_Radar();
            break;
        case self::STRATEGY_GOOGLE . Common_Chart::TYPE_ANALOG:
            $obj_strategy = new Common_Chart_Strategy_Google_Analog();
            break;
        case self::STRATEGY_GOOGLE . Common_Chart::TYPE_SCATTER:
            $obj_strategy = new Common_Chart_Strategy_Google_Scatter();
            break;
        case self::STRATEGY_GOOGLE . Common_Chart::TYPE_SCATTER_TREND:
            $obj_strategy = new Common_Chart_Strategy_Google_Scatter_Trend();
            break;
        }

        return $obj_strategy;
    }

}
